package TCP.Case;


import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Sever {
    public static void main(String[] args) {
        System.out.println("服务端启动...");
       ExecutorService executor = new ThreadPoolExecutor(3,
               4,6, TimeUnit.SECONDS,
               new ArrayBlockingQueue<>(2),new ThreadPoolExecutor.AbortPolicy());//创建线程池
        try {
            ServerSocket serverSocket = new ServerSocket(7777);//被别人访问端口
            while (true){
                Socket accept = serverSocket.accept();//等待客户端的请求 进行接受(停滞等待)建立socket通信管道
                /*new CommunicationThread(accept).start();*///每来一个用户就创建一个子线程
                executor.execute(new CommunicationRunnable(accept));//把任务交给线程池
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
